package ModelLayer;

import java.util.ArrayList;

public class VareCollectionModel {

    private ArrayList<VareModel> vareListe;
    private static VareCollectionModel instance;

    //Constructor
    private VareCollectionModel() {
        vareListe = new ArrayList<VareModel>();
        opretVarer();
    }

    public static VareCollectionModel getInstance(){
        if(instance == null){
            instance = new VareCollectionModel();
        }

        return instance;
    }

    //Methods
    public ArrayList<VareModel> getVareListe() {
        return vareListe;
    }

    private void opretVarer(){
        vareListe.add(new VareModel(11111, 99.99, "Hammer"));
        vareListe.add(new VareModel(11112, 49.99, "Søm"));
        vareListe.add(new VareModel(11113, 199.99, "Sav"));
        vareListe.add(new VareModel(11114, 999.99, "Boremaskine"));
        vareListe.add(new VareModel(11115, 69.99, "Skruer"));
    }

    public void printVarer(){
        for(VareModel v : vareListe){
            System.out.println(v.getId() + " " + v.getBeskrivelse() + " " + v.getPris());
        }
    }

    public VareModel findVare(int id) {
        for (VareModel v : vareListe){
            if(v.getId() == id){
                return v;
            }
        }
        return null;
    }
}
